package itpenguin.entities;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

@PersistenceCapable(detachable="true")
public class Article extends Content{

	public List<String> getSections() {
		return sections;
	}
	public void setSections(List<String> sections) {
		this.sections = sections;
	}
	
	@Persistent
	private List<String> sections = new ArrayList<String>();
	
	@Override
	public String getContextName() {
		return "articles";
	}
	
	@Override
	public boolean equals(Object obj) {
		
		Article a = (Article)obj;
		
		if (! a.getTitle().equals(getTitle())) return false;
		if (! a.getPublished().equals(getPublished())) return false;
		if (! a.getDescription().equals(getDescription())) return false;
		if (a.getSections().size() != sections.size()) return false;
		
		for(int i = 0; i < sections.size(); i++) {
			if (! sections.get(i).equals(a.getSections().get(i))) return false;
		}
		
		return true;
	}
	public int getPartNumber() {
		return partNumber;
	}
	public void setPartNumber(int partNumber) {
		this.partNumber = partNumber;
	}
	@Persistent
	private int partNumber;
	
	@Persistent(mappedBy = "article")
	@Element(dependent = "true")
	private List<ImageSrc> imageMap = new ArrayList<ImageSrc>();

	public List<ImageSrc> getImageMap() {
		return imageMap;
	}
	public void setImageMap(List<ImageSrc> imageMap) {
		this.imageMap = imageMap;
	}	
}
